<?php
/*
	用户
*/
namespace jy_yxw;
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\PhpWord;
defined('BY_JYA') or exit('error');
class uppdf extends \plugin{
	function dangan($id,$to_file=false){
		$item=pdo_get('jy_yxw_yonghu',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['createtime']=date('Y-m-d',$item['createtime']);
		$item['cent_tj']=str_replace("\n","<br/>",$item['cent_tj']);
		$item['cent_xm']=str_replace("\n","<br/>",$item['cent_xm']);
		$item['cent_mb']=str_replace("\n","<br/>",$item['cent_mb']);
		$item['cent_jh']=str_replace("\n","<br/>",$item['cent_jh']);
		$item['cent_jy']=str_replace("\n","<br/>",$item['cent_jy']);
		$item['cent_mb_data']=$item['cent_mb_data']?json_decode($item['cent_mb_data'],true):array();
		$cent_mb_datahtml="";
		foreach($item['cent_mb_data'] as $k=>$wv){
			$wv['data3']=str_replace("\n","<br/>",$wv['data3']);
			$cent_mb_datahtml .=<<<EOF
				<tr>  
				  <td>{$wv['data1']}</td>  
				  <td>{$wv['data2']}</td>  
				  <td>{$wv['data3']}</td>  
				  <td>{$wv['data4']}</td> 
			   </tr> 
EOF;
		}
		$item['cent_workers']=$item['cent_workers']?json_decode($item['cent_workers'],true):array();
		$cent_workershtml="";
		foreach($item['cent_workers'] as $k=>$wv){
			$index=$k+1;
			$cent_workershtml .=<<<EOF
				<tr>  
				  <td width="16.6%">{$index}</td>  
				  <td width="16.6%">{$wv['name']}</td>  
				  <td width="16.6%">{$wv['zhiwu']}</td>  
				  <td width="16.6%">{$wv['danwei']}</td>
				  <td width="16.6%">{$wv['desc']}</td>
				  <td width="17%">{$wv['mobile']}</td>
			   </tr>
EOF;
		}
		$user=pdo_get('jy_baobiao_project_cuser',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['user_id']));
		$item['user']=$user;
		$basic=$this->plugin_setting('basic');
		$basic['pdfshuo']=str_replace("\n","<br/>",$basic['pdfshuo']);
		$pdftitle=$basic['pdftitle']?:'某某市科普项目申报书';
		require ROOT_PLUGIN.'jy_tcpdf/vendor/autoload.php';
		// create new PDF document
		$pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', true);
		// set document information
		$pdf->setCreator(PDF_CREATOR);
		$pdf->setAuthor('Nicola Asuni');
		$pdf->setTitle($item['title'].'申请报表');
		$pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
		// set margins
		$pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
		$pdf->setPrintHeader(false);
		$pdf->setPrintFooter(false);
		// set auto page breaks
		$pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
		// set image scale factor
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
		// set some language-dependent strings (optional)
		if (@file_exists(ROOT_PLUGIN.'jy_tcpdf/vendor/tecnickcom/tcpdf/examples/lang/eng.php')) {
			require_once(ROOT_PLUGIN.'jy_tcpdf/vendor/tecnickcom/tcpdf/examples/lang/eng.php');
			$pdf->setLanguageArray($l);
		}		
		// add a page
		$pdf->AddPage();
		$html = <<<EOF
			<h3 style="text-align:right">项目编号：______________<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			</h3>
			<h1 style="text-align:center;font-size:36px">{$pdftitle}<br/></h1>  
			<h3 style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项目名称：{$item['title']}</h3>  
			<h3 style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 申报单位：{$item['user']['cname']}</h3>  
			<h3 style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 申报日期：{$item['createtime']}
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
			</h3>
			<br pagebreak="true" />
			<p>&nbsp;&nbsp;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></p>
			<h1 style="text-align:center;font-size:30px">填 表 说 明</h1>
			<h2 style="line-height:30px">{$basic['pdfshuo']}</h2>
			<br pagebreak="true" />
			<table border="1" cellpadding="10" style="width:100%;table-layout:fixed;word-wrap:break-word;">  
				<tr>  
				  <td>项目名称</td>  
				  <td colspan="3">{$item['title']}</td>   
			   </tr>
			   <tr>  
				  <td>申报单位</td>  
				  <td colspan="3">{$item['user']['cname']}</td>   
			   </tr> 
			   <tr>  
				  <td>项目负责人</td>  
				  <td>{$item['wname']}</td>  
				  <td>职务职称</td>  
				  <td>{$item['wcheng']}</td> 
			   </tr>
			   <tr>  
				  <td>联系电话</td>  
				  <td>{$item['wtel']}</td>  
				  <td>移动电话</td>  
				  <td>{$item['wmobile']}</td> 
			   </tr>
			   <tr>  
				  <td>联系人</td>  
				  <td>{$item['user']['name']}</td>  
				  <td>联系电话</td>  
				  <td>{$item['user']['mobile']}</td> 
			   </tr> 
			   <tr>  
				  <td>移动电话</td>  
				  <td>{$item['user']['mobile']}</td>  
				  <td>电子邮箱</td>  
				  <td>{$item['user']['email']}</td> 
			   </tr> 
			   <tr><td style="text-align:left" colspan="4">一、申报条件</td></tr>  
			   <tr><td style="text-align:left" colspan="4"><p style="font-size:15px;line-height:25px">{$item['cent_tj']}</p><br/><br/></td></tr>
			   <tr><td style="text-align:left" colspan="4">二、项目主要内容</td></tr>
			   <tr><td style="text-align:left" colspan="4"><p style="font-size:15px;line-height:25px">{$item['cent_xm']}</p><br/><br/></td></tr>
			   <tr><td style="text-align:left" colspan="4">三、项目目标及预期成效</td></tr>
			   <tr><td style="text-align:left" colspan="4"><p style="font-size:15px;line-height:25px">{$item['cent_mb']}</p><br/><br/></td></tr>
				<tr>  
				  <td>一级指标</td>  
				  <td>二级指标</td>  
				  <td>三级指标</td>  
				  <td>指标值</td> 
			   </tr>
			   {$cent_mb_datahtml}
			   <tr><td style="text-align:left" colspan="4">四、项目经费预算</td></tr>
			   <tr><td style="text-align:left" colspan="4">总预算&nbsp;&nbsp;&nbsp;&nbsp;{$item['cent_fee1']}&nbsp;&nbsp;&nbsp;&nbsp;元，其中：单位自筹&nbsp;&nbsp;&nbsp;&nbsp;{$item['cent_fee2']}&nbsp;&nbsp;&nbsp;&nbsp;元</td></tr>
			   <tr><td style="text-align:left" colspan="4">五、项目实施步骤、进度计划</td></tr>
			   <tr><td style="text-align:left" colspan="4"><p style="font-size:15px;line-height:25px">{$item['cent_jh']}</p><br/><br/></td></tr>
			   <tr><td style="text-align:left" colspan="4">六、项目负责人及主要参加人员</td></tr>
			   <tr>  
				  <td width="16.6%">序号</td>  
				  <td width="16.6%">姓名</td>  
				  <td width="16.6%">职务职称</td>  
				  <td width="16.6%">工作单位</td>
				  <td width="16.6%">项目中承担的主要工作</td>
				  <td width="17%">联系方式</td>
			   </tr>
			   {$cent_workershtml}
			   <tr><td style="text-align:left;width:100%" colspan="6">七、项目申报单位意见</td></tr>
			   <tr>
			   <td style="text-align:left;width:100%" colspan="6">
						{$item['cent_jy']}
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<p style="text-align:right;margin-top:100px;">单位负责人（签名）：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
						<p style="text-align:right;">单位公章：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
						<p style="text-align:right;">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
			   </td>
			   </tr>
			   <br pagebreak="true" />
			   <tr><td style="text-align:left;width:100%" colspan="6">八、市科协部门审查意见</td></tr>
			   <tr>
			   <td style="text-align:left;width:100%" colspan="6">
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<p style="text-align:right;">部长：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
						<p style="text-align:right;">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
			   </td>
			   </tr>
			   <tr><td style="text-align:left;width:100%" colspan="6">九、市科协分管主席审批意见</td></tr>
			   <tr>
			   <td style="text-align:left;width:100%" colspan="6">
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<p style="text-align:right;">负责人：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
						<p style="text-align:right;">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
			   </td>
			   </tr>
			   <tr><td style="text-align:left;width:100%" colspan="6">十、市科协负责人审批意见</td></tr>
			   <tr>
			   <td style="text-align:left;width:100%" colspan="6">
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<br/>
						<p style="text-align:right;">负责人：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
						<p style="text-align:right;">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
			   </td>
			   </tr>
			</table>
EOF;
		$pdf->SetFont('msyh', '', 12, '', true);
		$pdf->writeHTML($html,  true, false, true, false, '');
		$pdf->lastPage();
		$pdf->Output($item['title'].'档案表.pdf', 'I');
		exit;
	}
}